package org.elephas.webapp.model;

import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.elephas.model.BlogMembership;
import org.elephas.service.UserFinder;

import salve.contract.NotNull;
import salve.depend.Dependency;

/**
 * A loadable detachable {@link IModel} for {@link BlogMembership}s.
 * 
 * @author Gerolf Seitz
 * 
 */
public class DetachableBlogMembershipModel extends
		LoadableDetachableModel<BlogMembership> {
	private static final long serialVersionUID = 1L;

	@Dependency
	private UserFinder finder;

	private String uuid;

	public DetachableBlogMembershipModel() {
	}

	public DetachableBlogMembershipModel(@NotNull BlogMembership ms) {
		uuid = ms.getUuid();
	}

	@Override
	protected BlogMembership load() {
		if (uuid == null) {
			return new BlogMembership();
		}
		return finder.findMembershipByUuid(uuid);
	}
}
